
package simdemo;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.TimerTask;
import javax.swing.JOptionPane;
import javax.swing.Timer;
import javax.swing.UIManager;

/**
 *
 * @author Kevin Doyle
 */
public class SimJFrame extends javax.swing.JFrame implements ActionListener {

    public void upDateExocetSystemIndicators() {
        jLOBC_ADDAIFs.setText("Go");
        jLOBC_MIL1553IFs.setText("Go");
        jLOBC_MILBUS.setText("Go");
        jLOBC_OBTClocks.setText("Go");
        jLOBC_Processors.setText("Go");
        jLOBC_UARTS.setText("Go");
        jLSysHealth_AOCS.setText("Go");
        jLSysHealth_AirFrame.setText("Go");
        jLSysHealth_Battery.setText("Go");
        jLSysHealth_GPS.setText("Go");
        jLSysHealth_INS.setText("Go");
        jLSysHealth_Launcher.setText("Go");
        jLSysHealth_RADAR.setText("Go");
        jLSysHealth_RocketMotor.setText("Go");
        jLOBC_ADDAIFs.setForeground(Color.green);
        jLOBC_MIL1553IFs.setForeground(Color.green);
        jLOBC_MILBUS.setForeground(Color.green);
        jLOBC_OBTClocks.setForeground(Color.green);
        jLOBC_Processors.setForeground(Color.green);
        jLOBC_UARTS.setForeground(Color.green);
        jLSysHealth_AOCS.setForeground(Color.green);
        jLSysHealth_AirFrame.setForeground(Color.green);
        jLSysHealth_Battery.setForeground(Color.green);
        jLSysHealth_GPS.setForeground(Color.green);
        jLSysHealth_INS.setForeground(Color.green);
        jLSysHealth_Launcher.setForeground(Color.green);
        jLSysHealth_RADAR.setForeground(Color.green);
        jLSysHealth_RocketMotor.setForeground(Color.green);


    }
    double launchLatitude, launchLongitude, targetLatitude, targetLongitude,
            groundRange, forwardAzimuth, latitudeN, longitudeN, distanceFromLaunch,
            operationalFlightRange = 200000;//200Km
    StringBuffer sb = new StringBuffer();
    SoundEventPlayer sep1;
    SoundEventPlayer sep2;
    SoundEventPlayer sep3;
    Timer exocetRadarBlipTimer;//timer for checking for all over system messages
    Timer radarBlipTimer;
    Timer exocetTelemetry;

    /**
     * Creates new form SimJFrame
     */
    public SimJFrame() {

        initComponents();
       
        sep1 = new SoundEventPlayer();
        sep2 = new SoundEventPlayer();
        sep3 = new SoundEventPlayer();

        exocetRadarBlipTimer = new Timer(3000, this);//output output messages 
        exocetRadarBlipTimer.setActionCommand("exocetRadarBlip");
        radarBlipTimer = new Timer(2500, this);//output output messages 
        radarBlipTimer.setActionCommand("CIWSRADAR");
        radarBlipTimer.start();
        exocetTelemetry = new Timer(1000, this);
        exocetTelemetry.setActionCommand("TELEMETRY");




    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialogMissionData = new javax.swing.JDialog();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLSysHealth_AirFrame = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLSysHealth_RADAR = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLSysHealth_AOCS = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLSysHealth_RocketMotor = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLSysHealth_GPS = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLSysHealth_Launcher = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLSysHealth_INS = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLSysHealth_Battery = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jLabel22 = new javax.swing.JLabel();
        jLOBC_ADDAIFs = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        jLOBC_OBTClocks = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jLOBC_MILBUS = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLOBC_Processors = new javax.swing.JLabel();
        jLabel32 = new javax.swing.JLabel();
        jLOBC_MIL1553IFs = new javax.swing.JLabel();
        jLabel30 = new javax.swing.JLabel();
        jLOBC_UARTS = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jLabel34 = new javax.swing.JLabel();
        jLLaunchLat = new javax.swing.JLabel();
        jLabel35 = new javax.swing.JLabel();
        jLLaunchLong = new javax.swing.JLabel();
        jLabel37 = new javax.swing.JLabel();
        jLLaunchAlt = new javax.swing.JLabel();
        jLabel39 = new javax.swing.JLabel();
        jLTargetLat = new javax.swing.JLabel();
        jLabel42 = new javax.swing.JLabel();
        jLTargetLong = new javax.swing.JLabel();
        jLabel44 = new javax.swing.JLabel();
        jLTargetRange = new javax.swing.JLabel();
        jLabel46 = new javax.swing.JLabel();
        jLTargetAzimuth = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        jLabel49 = new javax.swing.JLabel();
        jLabel48 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel9 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTP_ExocetSystemLog = new javax.swing.JTextPane();
        jPanel3 = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        rADARScreen1 = new simdemo.RADARScreen();
        jPanel11 = new javax.swing.JPanel();
        rADARScreen2 = new simdemo.RADARScreen();
        jPanel12 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTPGoalKeeperSysLog = new javax.swing.JTextPane();
        jPanel13 = new javax.swing.JPanel();

        javax.swing.GroupLayout jDialogMissionDataLayout = new javax.swing.GroupLayout(jDialogMissionData.getContentPane());
        jDialogMissionData.getContentPane().setLayout(jDialogMissionDataLayout);
        jDialogMissionDataLayout.setHorizontalGroup(
            jDialogMissionDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jDialogMissionDataLayout.setVerticalGroup(
            jDialogMissionDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("© Kevin Doyle 2012, Limerick, Ireland - - MBDA Exocet Versus Thales Goalkeeper (HMS Sheffield)");
        setBounds(new java.awt.Rectangle(0, 0, 1080, 600));
        setMaximizedBounds(new java.awt.Rectangle(0, 0, 1080, 600));
        setMaximumSize(new java.awt.Dimension(1080, 600));
        setMinimumSize(new java.awt.Dimension(1080, 600));
        setResizable(false);

        jTabbedPane1.setMaximumSize(new java.awt.Dimension(1080, 600));
        jTabbedPane1.setMinimumSize(new java.awt.Dimension(1080, 600));
        jTabbedPane1.setName("Hello");
        jTabbedPane1.setPreferredSize(new java.awt.Dimension(1080, 600));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/formattedText.PNG"))); // NOI18N

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/exocet.png"))); // NOI18N
        jLabel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Exocet", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jLabel3.setText("jLabel3");

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/hmsSheffieldD80.png"))); // NOI18N
        jLabel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "HMS Sheffield", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/goalkeeper.png"))); // NOI18N
        jLabel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Goalkeeper", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Mission Panel", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jButton1.setText("Enter GPS Data");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(125, 125, 125)
                .addComponent(jButton1)
                .addContainerGap(97, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jLabel3))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel2)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel5)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel4))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(51, 51, 51)
                                .addComponent(jLabel1)))
                        .addGap(18, 18, 18)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel1))
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(502, 502, 502)
                .addComponent(jLabel3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Project Intro", jPanel1);

        jPanel2.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                jPanel2ComponentShown(evt);
            }
        });

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "System Health", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
        jPanel5.setLayout(new java.awt.GridLayout(4, 4));

        jLabel6.setText("Airframe:");
        jPanel5.add(jLabel6);

        jLSysHealth_AirFrame.setText("..");
        jPanel5.add(jLSysHealth_AirFrame);

        jLabel14.setText("RADAR:");
        jPanel5.add(jLabel14);

        jLSysHealth_RADAR.setText("..");
        jPanel5.add(jLSysHealth_RADAR);

        jLabel9.setText("AOCS:");
        jPanel5.add(jLabel9);

        jLSysHealth_AOCS.setText("..");
        jPanel5.add(jLSysHealth_AOCS);

        jLabel18.setText("Rocket Motor:");
        jPanel5.add(jLabel18);

        jLSysHealth_RocketMotor.setText("..");
        jPanel5.add(jLSysHealth_RocketMotor);

        jLabel11.setText("GPS:");
        jPanel5.add(jLabel11);

        jLSysHealth_GPS.setText("..");
        jPanel5.add(jLSysHealth_GPS);

        jLabel13.setText("Launcher:");
        jPanel5.add(jLabel13);

        jLSysHealth_Launcher.setText("..");
        jPanel5.add(jLSysHealth_Launcher);

        jLabel17.setText("INS:");
        jPanel5.add(jLabel17);

        jLSysHealth_INS.setText("..");
        jPanel5.add(jLSysHealth_INS);

        jLabel20.setText("Battery:");
        jPanel5.add(jLabel20);

        jLSysHealth_Battery.setText("..");
        jPanel5.add(jLSysHealth_Battery);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "OBC", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
        jPanel6.setLayout(new java.awt.GridLayout(3, 4));

        jLabel22.setText("AD/DA IFs:");
        jPanel6.add(jLabel22);

        jLOBC_ADDAIFs.setText("..");
        jPanel6.add(jLOBC_ADDAIFs);

        jLabel28.setText("OBT Clocks:");
        jPanel6.add(jLabel28);

        jLOBC_OBTClocks.setText("..");
        jPanel6.add(jLOBC_OBTClocks);

        jLabel27.setText("MIL Bus:");
        jPanel6.add(jLabel27);

        jLOBC_MILBUS.setText("..");
        jPanel6.add(jLOBC_MILBUS);

        jLabel23.setText("Processors:");
        jPanel6.add(jLabel23);

        jLOBC_Processors.setText("..");
        jPanel6.add(jLOBC_Processors);

        jLabel32.setText("MIL 1553 IFs:");
        jPanel6.add(jLabel32);

        jLOBC_MIL1553IFs.setText("..");
        jPanel6.add(jLOBC_MIL1553IFs);

        jLabel30.setText("UARTs:");
        jPanel6.add(jLabel30);

        jLOBC_UARTS.setText("..");
        jPanel6.add(jLOBC_UARTS);

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Initialisation Data", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jLabel34.setText("Launch Latitude:");

        jLLaunchLat.setText("..");

        jLabel35.setText("Launch Longitude:");

        jLLaunchLong.setText("..");

        jLabel37.setText("Launch Altitude:");

        jLLaunchAlt.setText("..");

        jLabel39.setText("Target Latitude:");

        jLTargetLat.setText("..");

        jLabel42.setText("Target Longitude:");

        jLTargetLong.setText("..");

        jLabel44.setText("Target Range:");

        jLTargetRange.setText("..");

        jLabel46.setText("Target Azimuth:");

        jLTargetAzimuth.setText("..");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel34)
                        .addGap(18, 18, 18)
                        .addComponent(jLLaunchLat, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel39, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel37, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLLaunchAlt, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLTargetLat, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel42, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel35, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(jLabel46))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLTargetAzimuth, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLLaunchLong, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLTargetLong, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(34, 44, Short.MAX_VALUE))
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(jLabel44)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLTargetRange, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGap(1, 1, 1)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel34, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLLaunchLat, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel35, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLLaunchLong, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel37, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLLaunchAlt, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel39, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLTargetLat, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel42, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLTargetLong, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel44, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLTargetRange, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel46, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLTargetAzimuth, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Exocet Launcher", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(255, 0, 0)));

        jLabel49.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/exocetMM40.png"))); // NOI18N

        jLabel48.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/exocetMM40.png"))); // NOI18N

        jButton2.setText("Fire Exocet 1");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Fire Exocet 2");

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel48)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addGap(172, 172, 172)
                .addComponent(jLabel49)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel48)
                    .addComponent(jLabel49)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton2)
                        .addGap(36, 36, 36)
                        .addComponent(jButton3)))
                .addGap(7, 7, 7))
        );

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Exocet System Log", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jScrollPane1.setViewportView(jTP_ExocetSystemLog);

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)
                            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)))
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                                .addGap(13, 13, 13)
                                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(16, 16, 16))
        );

        jTabbedPane1.addTab("Exocet Control", jPanel2);

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search RADAR", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        javax.swing.GroupLayout rADARScreen1Layout = new javax.swing.GroupLayout(rADARScreen1);
        rADARScreen1.setLayout(rADARScreen1Layout);
        rADARScreen1Layout.setHorizontalGroup(
            rADARScreen1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 255, Short.MAX_VALUE)
        );
        rADARScreen1Layout.setVerticalGroup(
            rADARScreen1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 255, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(rADARScreen1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addComponent(rADARScreen1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        jPanel11.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tracking RADAR", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        javax.swing.GroupLayout rADARScreen2Layout = new javax.swing.GroupLayout(rADARScreen2);
        rADARScreen2.setLayout(rADARScreen2Layout);
        rADARScreen2Layout.setHorizontalGroup(
            rADARScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 255, Short.MAX_VALUE)
        );
        rADARScreen2Layout.setVerticalGroup(
            rADARScreen2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 255, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel11Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(rADARScreen2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addComponent(rADARScreen2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 11, Short.MAX_VALUE))
        );

        jPanel12.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Goalkeeper system Log", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jScrollPane2.setViewportView(jTPGoalKeeperSysLog);

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addComponent(jScrollPane2)
                .addContainerGap())
        );

        jPanel13.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "GoalKeeper Engage", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(255, 0, 0)));

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 218, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jPanel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addComponent(jPanel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Goalkeeper Control", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String tags[] = {
            "Launch LATitude", "Launch LONgitude", "Target LATitude", "Target LONgitude"
        };
        String dialog = " ";
        for (int i = 0; i <= 3; i++) {
            if (i == 0) {
                dialog = tags[0];
            }
            if (i == 1) {
                dialog = tags[1];
            }
            if (i == 2) {
                dialog = tags[2];
            }
            if (i == 3) {
                dialog = tags[3];
            }
            String s = (String) JOptionPane.showInputDialog(jDialogMissionData, (new StringBuilder()).append("Enter: ").append(dialog).toString(), "Mission Data...", -1, null, null, null);
            if (i == 0) {
                launchLatitude = Double.parseDouble(s);
            }
            if (i == 1) {
                launchLongitude = Double.parseDouble(s);
            }
            if (i == 2) {
                targetLatitude = Double.parseDouble(s);
            }
            if (i == 3) {
                targetLongitude = Double.parseDouble(s);
            }
        }
        
   
              onBoardComputer();
      
        
        
        
        jTabbedPane1.setSelectedComponent(jPanel2);//switch to next panel
        upDateExocetGUIPanel();
          
               printCalculatedTrack();
    
        

    }//GEN-LAST:event_jButton1ActionPerformed

    private void printCalculatedTrack(){
       
        
       jTP_ExocetSystemLog.setText(sb.substring(0, sb.length()));
       
  

        
        
    }
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
      

                sep1.setLaunchSound(1);//play the launch sound
                exocetRadarBlipTimer.start();//start emitting events to trigger radar sounds
                sep3.setLaunchSound(2);//start repeated play of exocet radar blip
                exocetTelemetry.start();

    }//GEN-LAST:event_jButton2ActionPerformed

    private void jPanel2ComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jPanel2ComponentShown
 java.util.Timer setExocetStatuses = new java.util.Timer("Set Exocet Statuses", false);
        setExocetStatuses.schedule(new TimerTask() {

            @Override
            public void run() {
               upDateExocetSystemIndicators();
            }
        }, 2500L);

        
    }//GEN-LAST:event_jPanel2ComponentShown

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SimJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SimJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SimJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SimJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new SimJFrame().setVisible(true);
            }
        });
    }

    public void onBoardComputer() {
        groundRange = getGroundRange(launchLatitude, launchLongitude, targetLatitude, targetLongitude);

        forwardAzimuth = getForwardAzimuth(launchLatitude, launchLongitude, targetLatitude, targetLongitude);
        do {
            latitudeN = getNextLatitude(launchLatitude, launchLongitude, forwardAzimuth, distanceFromLaunch);
            longitudeN = getNextLongitude(launchLatitude, launchLongitude, forwardAzimuth, distanceFromLaunch);
            sb.append("(").append(latitudeN).append("°\t").append(longitudeN).append("°)\n");
            distanceFromLaunch++;
        } while (distanceFromLaunch < groundRange);
    }

    /*
     * public static void preFlightCheck(double rangeToTarget) { Boolean
     * preFlightCheckListCounter[] = new Boolean[10]; if(rangeToTarget >
     * operationalFlightRange) { preFlightCheckListCounter[0] =
     * Boolean.valueOf(false); throw new IllegalArgumentException("Operational
     * Range [excessive]"); } else { return;} }
     */
    public void upDateExocetGUIPanel() {
        jLLaunchAlt.setText("n/a");
        jLLaunchLat.setText(Double.toString(launchLatitude)+"°");
        jLLaunchLong.setText(Double.toString(launchLongitude)+"°");
        jLTargetAzimuth.setText(Double.toString(forwardAzimuth)+"°");
        jLTargetLat.setText(Double.toString(targetLatitude)+"°");
        jLTargetLong.setText(Double.toString(targetLongitude)+"°");
        jLTargetRange.setText(Double.toString(groundRange/1000)+"Km");

    }

    public static double getNextLatitude(double latitudeA, double longitudeA, double forwardAzimuth, double range) {
        double a = 6378160D;
        double b = 6356774.7189999996D;
        double f = (a - b) / a;
        double s = range;
        double alpha1 = Math.toRadians(forwardAzimuth);
        double sinAlpha1 = Math.sin(alpha1);
        double cosAlpha1 = Math.cos(alpha1);
        double tanU1 = (1.0D - f) * Math.tan(Math.toRadians(latitudeA));
        double cosU1 = 1.0D / Math.sqrt(1.0D + tanU1 * tanU1);
        double sinU1 = tanU1 * cosU1;
        double sigma1 = Math.atan2(tanU1, cosAlpha1);
        double sinAlpha = cosU1 * sinAlpha1;
        double cosSqAlpha = 1.0D - sinAlpha * sinAlpha;
        double uSq = (cosSqAlpha * (a * a - b * b)) / (b * b);
        double A = 1.0D + (uSq / 16384D) * (4096D + uSq * (-768D + uSq * (320D - 175D * uSq)));
        double B = (uSq / 1024D) * (256D + uSq * (-128D + uSq * (74D - 47D * uSq)));
        double sigma = s / (b * A);
        double sigmaP = 6.2831853071795862D;
        double sinSigma = Math.sin(sigma);
        double cosSigma = Math.cos(sigma);
        double cos2SigmaM = Math.cos(2D * sigma1 + sigma);
        double deltaSigma;
        for (; Math.abs(sigma - sigmaP) > 9.9999999999999998E-013D; sigma = s / (b * A) + deltaSigma) {
            cos2SigmaM = Math.cos(2D * sigma1 + sigma);
            sinSigma = Math.sin(sigma);
            cosSigma = Math.cos(sigma);
            deltaSigma = B * sinSigma * (cos2SigmaM + (B / 4D) * (cosSigma * (-1D + 2D * cos2SigmaM * cos2SigmaM) - (B / 6D) * cos2SigmaM * (-3D + 4D * sinSigma * sinSigma) * (-3D + 4D * cos2SigmaM * cos2SigmaM)));
            sigmaP = sigma;
        }

        double tmp = sinU1 * sinSigma - cosU1 * cosSigma * cosAlpha1;
        double nextLatitude = Math.atan2(sinU1 * cosSigma + cosU1 * sinSigma * cosAlpha1, (1.0D - f) * Math.sqrt(sinAlpha * sinAlpha + tmp * tmp));
        return Math.toDegrees(nextLatitude);
    }

    public static double getNextLongitude(double latitudeA, double longitudeA, double forwardAzimuth, double range) {
        double a = 6378160D;
        double b = 6356774.7189999996D;
        double f = (a - b) / a;
        double s = range;
        double alpha1 = Math.toRadians(forwardAzimuth);
        double sinAlpha1 = Math.sin(alpha1);
        double cosAlpha1 = Math.cos(alpha1);
        double tanU1 = (1.0D - f) * Math.tan(Math.toRadians(latitudeA));
        double cosU1 = 1.0D / Math.sqrt(1.0D + tanU1 * tanU1);
        double sinU1 = tanU1 * cosU1;
        double sigma1 = Math.atan2(tanU1, cosAlpha1);
        double sinAlpha = cosU1 * sinAlpha1;
        double cosSqAlpha = 1.0D - sinAlpha * sinAlpha;
        double uSq = (cosSqAlpha * (a * a - b * b)) / (b * b);
        double A = 1.0D + (uSq / 16384D) * (4096D + uSq * (-768D + uSq * (320D - 175D * uSq)));
        double B = (uSq / 1024D) * (256D + uSq * (-128D + uSq * (74D - 47D * uSq)));
        double sigma = s / (b * A);
        double sigmaP = 6.2831853071795862D;
        double sinSigma = Math.sin(sigma);
        double cosSigma = Math.cos(sigma);
        double cos2SigmaM = Math.cos(2D * sigma1 + sigma);
        double deltaSigma;
        for (; Math.abs(sigma - sigmaP) > 9.9999999999999998E-013D; sigma = s / (b * A) + deltaSigma) {
            cos2SigmaM = Math.cos(2D * sigma1 + sigma);
            sinSigma = Math.sin(sigma);
            cosSigma = Math.cos(sigma);
            deltaSigma = B * sinSigma * (cos2SigmaM + (B / 4D) * (cosSigma * (-1D + 2D * cos2SigmaM * cos2SigmaM) - (B / 6D) * cos2SigmaM * (-3D + 4D * sinSigma * sinSigma) * (-3D + 4D * cos2SigmaM * cos2SigmaM)));
            sigmaP = sigma;
        }

        double lambda = Math.atan2(sinSigma * sinAlpha1, cosU1 * cosSigma - sinU1 * sinSigma * cosAlpha1);
        double C = (f / 16D) * cosSqAlpha * (4D + f * (4D - 3D * cosSqAlpha));
        double L = lambda - (1.0D - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1D + 2D * cos2SigmaM * cos2SigmaM)));
        double nextLongitude = (Math.toRadians(longitudeA) + L + 9.4247779607693793D) % 6.2831853071795862D - 3.1415926535897931D;
        return Math.toDegrees(nextLongitude);
    }

    public static double getForwardAzimuth(double latitudeA, double longitudeA, double latitudeB, double longitudeB) {
        double a = 6378160D;
        double b = 6356774.7189999996D;
        double f = (a - b) / a;
        double L = Math.toRadians(longitudeB - longitudeA);
        double U1 = Math.atan((1.0D - f) * Math.tan(Math.toRadians(latitudeA)));
        double U2 = Math.atan((1.0D - f) * Math.tan(Math.toRadians(latitudeB)));
        double sinU1 = Math.sin(U1);
        double cosU1 = Math.cos(U1);
        double sinU2 = Math.sin(U2);
        double cosU2 = Math.cos(U2);
        double lambda = L;
        double iterLimit = 100D;
        double sinLambda = Math.sin(lambda);
        double cosLambda = Math.cos(lambda);
        double sinSigma = Math.sqrt(cosU2 * sinLambda * (cosU2 * sinLambda) + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda));
        double cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
        double sigma = Math.atan2(sinSigma, cosSigma);
        double sinAlpha = (cosU1 * cosU2 * sinLambda) / sinSigma;
        double cosSqAlpha = 1.0D - sinAlpha * sinAlpha;
        double cos2SigmaM = cosSigma - (2D * sinU1 * sinU2) / cosSqAlpha;
        double lambdaP;
        do {
            sinLambda = Math.sin(lambda);
            cosLambda = Math.cos(lambda);
            sinSigma = Math.sqrt(cosU2 * sinLambda * (cosU2 * sinLambda) + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda));
            if (sinSigma == 0.0D) {
                System.out.println("co-incident points");
            }
            cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
            sigma = Math.atan2(sinSigma, cosSigma);
            sinAlpha = (cosU1 * cosU2 * sinLambda) / sinSigma;
            cosSqAlpha = 1.0D - sinAlpha * sinAlpha;
            cos2SigmaM = cosSigma - (2D * sinU1 * sinU2) / cosSqAlpha;
            if (Double.isNaN(cos2SigmaM)) {
                cos2SigmaM = 0.0D;
            }
            double C = (f / 16D) * cosSqAlpha * (4D + f * (4D - 3D * cosSqAlpha));
            lambdaP = lambda;
            lambda = L + (1.0D - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1D + 2D * cos2SigmaM * cos2SigmaM)));
        } while (Math.abs(lambda - lambdaP) > 9.9999999999999998E-013D && --iterLimit > 0.0D);
        if (iterLimit == 0.0D) {
            System.out.println("NaN iterLimit==0 \n formula failed to converge");
        }
        double fwdAz = Math.atan2(cosU2 * sinLambda, cosU1 * sinU2 - sinU1 * cosU2 * cosLambda);
        return Math.toDegrees(fwdAz);
    }

    public static double getGroundRange(double latitudeA, double longitudeA, double latitudeB, double longitudeB) {
        double a = 6378160D;
        double b = 6356774.7189999996D;
        double f = (a - b) / a;
        double L = Math.toRadians(longitudeB - longitudeA);
        double U1 = Math.atan((1.0D - f) * Math.tan(Math.toRadians(latitudeA)));
        double U2 = Math.atan((1.0D - f) * Math.tan(Math.toRadians(latitudeB)));
        double sinU1 = Math.sin(U1);
        double cosU1 = Math.cos(U1);
        double sinU2 = Math.sin(U2);
        double cosU2 = Math.cos(U2);
        double lambda = L;
        double iterLimit = 100D;
        double sinLambda = Math.sin(lambda);
        double cosLambda = Math.cos(lambda);
        double sinSigma = Math.sqrt(cosU2 * sinLambda * (cosU2 * sinLambda) + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda));
        double cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
        double sigma = Math.atan2(sinSigma, cosSigma);
        double sinAlpha = (cosU1 * cosU2 * sinLambda) / sinSigma;
        double cosSqAlpha = 1.0D - sinAlpha * sinAlpha;
        double cos2SigmaM = cosSigma - (2D * sinU1 * sinU2) / cosSqAlpha;
        double lambdaP;
        do {
            sinLambda = Math.sin(lambda);
            cosLambda = Math.cos(lambda);
            sinSigma = Math.sqrt(cosU2 * sinLambda * (cosU2 * sinLambda) + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda));
            if (sinSigma == 0.0D) {
                System.out.println("co-incident points");
            }
            cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
            sigma = Math.atan2(sinSigma, cosSigma);
            sinAlpha = (cosU1 * cosU2 * sinLambda) / sinSigma;
            cosSqAlpha = 1.0D - sinAlpha * sinAlpha;
            cos2SigmaM = cosSigma - (2D * sinU1 * sinU2) / cosSqAlpha;
            if (Double.isNaN(cos2SigmaM)) {
                cos2SigmaM = 0.0D;
            }
            double C = (f / 16D) * cosSqAlpha * (4D + f * (4D - 3D * cosSqAlpha));
            lambdaP = lambda;
            lambda = L + (1.0D - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1D + 2D * cos2SigmaM * cos2SigmaM)));
        } while (Math.abs(lambda - lambdaP) > 9.9999999999999998E-013D && --iterLimit > 0.0D);
        if (iterLimit == 0.0D) {
            System.out.println("NaN iterLimit==0 \n formula failed to converge");
        }
        double uSq = (cosSqAlpha * (a * a - b * b)) / (b * b);
        double A = 1.0D + (uSq / 16384D) * (4096D + uSq * (-768D + uSq * (320D - 175D * uSq)));
        double B = (uSq / 1024D) * (256D + uSq * (-128D + uSq * (74D - 47D * uSq)));
        double deltaSigma = B * sinSigma * (cos2SigmaM + (B / 4D) * (cosSigma * (-1D + 2D * cos2SigmaM * cos2SigmaM) - (B / 6D) * cos2SigmaM * (-3D + 4D * sinSigma * sinSigma) * (-3D + 4D * cos2SigmaM * cos2SigmaM)));
        double s = b * A * (sigma - deltaSigma);
        return s;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JDialog jDialogMissionData;
    private javax.swing.JLabel jLLaunchAlt;
    private javax.swing.JLabel jLLaunchLat;
    private javax.swing.JLabel jLLaunchLong;
    private javax.swing.JLabel jLOBC_ADDAIFs;
    private javax.swing.JLabel jLOBC_MIL1553IFs;
    private javax.swing.JLabel jLOBC_MILBUS;
    private javax.swing.JLabel jLOBC_OBTClocks;
    private javax.swing.JLabel jLOBC_Processors;
    private javax.swing.JLabel jLOBC_UARTS;
    private javax.swing.JLabel jLSysHealth_AOCS;
    private javax.swing.JLabel jLSysHealth_AirFrame;
    private javax.swing.JLabel jLSysHealth_Battery;
    private javax.swing.JLabel jLSysHealth_GPS;
    private javax.swing.JLabel jLSysHealth_INS;
    private javax.swing.JLabel jLSysHealth_Launcher;
    private javax.swing.JLabel jLSysHealth_RADAR;
    private javax.swing.JLabel jLSysHealth_RocketMotor;
    private javax.swing.JLabel jLTargetAzimuth;
    private javax.swing.JLabel jLTargetLat;
    private javax.swing.JLabel jLTargetLong;
    private javax.swing.JLabel jLTargetRange;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel42;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JLabel jLabel46;
    private javax.swing.JLabel jLabel48;
    private javax.swing.JLabel jLabel49;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextPane jTPGoalKeeperSysLog;
    private javax.swing.JTextPane jTP_ExocetSystemLog;
    private javax.swing.JTabbedPane jTabbedPane1;
    private simdemo.RADARScreen rADARScreen1;
    private simdemo.RADARScreen rADARScreen2;
    // End of variables declaration//GEN-END:variables

    @Override
    public void actionPerformed(ActionEvent e) {

        if (e.getActionCommand().equalsIgnoreCase("CIWSRADAR")) {
            sep2.setLaunchSound(4);//play the 1 sec repeated radar alt sound
        }
    }
}
